package engine.shader;

import java.util.HashMap;
import java.util.Map;

public class DefaultShader extends Shader{

	private static boolean initialized = false;
	
	public DefaultShader() {
		super("shader/engine/default/vertexLighting.shader", getAttributes());
		
		if(!initialized) {
			init();
			
			initialized = true;
		}
	}
	
	private void init() {
		enable();
		sendUniform1i("tex", 0);
		sendUniform1i("maxLights", 0);
		sendUniform1i("useTexture", 0);
		
		//send default material
		sendUniform4f("material.ambient", 0, 0, 0, 0);
		sendUniform4f("material.diffuse", 0, 0, 0, 0);
		sendUniform4f("material.specular", 0, 0, 0, 0);
		sendUniform4f("material.emissive", 0, 0, 0, 0);
		
		//send default lights
		for(int i = 0; i < 8; i++) {
			sendUniform4f("lights[" + i + "].ambient", 0, 0, 0, 0);
			sendUniform4f("lights[" + i + "].diffuse", 0, 0, 0, 0);
			sendUniform4f("lights[" + i + "].position", 0, 0, 0, 0);
			sendUniform4f("lights[" + i + "].specular", 0, 0, 0, 0);
			sendUniform1f("lights[" + i + "].shininess", 0);
		}
		
		disable();
	}

	private static Map<Integer, String> getAttributes() {
		Map<Integer, String> map = new HashMap<Integer, String>();
		
		map.put(0, "vertex_in");
		map.put(1, "texcoord_in");
		map.put(2, "normal_in");
		
		return map;
	}

}
